'''
使用 while 和 for…in 两个循环分别输出四种九九乘法表效果（共计 8 个）
思想：
一共有两种可以使用的循环结构,<while while> <for while> <for for> < whlie for>
用上述方法个完成两种不同的乘法表三角形
l -> ligne 行
c -> colonne  列
'''


''' 
1
三角方向向右 双while循环
'''
print("三角方向向右 双while循环")
l = 1
c = 1
while l<=9:
    while c<=l:
        print('{:1}*{:1} = {:<4}'.format(l,c,l*c),end=' ')
        c+=1
    print('')
    c = 1
    l+=1
print('=='*60,'\n')

l = 9
c = 1
while l>=1:
    while c<=l:
        print('{}*{} = {:<4}'.format(l,c,l*c),end=' ')
        c+=1
    print()
    c = 1
    l-=1


'''
2
三角方向向左 双while循环
'''
print('***'*50,'\n\n')
print('三角方向向左 双while循环')

l = 1
c = 9
while l<=9 :
    while c>=1 :
        if c>l:
            print(' '*10,end=' ')
        else:
            print('{}*{} = {:<4}'.format(l,c,c*l),end=' ')
        c-=1
    print('')
    c = 9
    l+=1
print('=='*60,'\n')

l = 9
c = 9
while l>=1 :
    while c>=1 :
        if c>l:
            print(' '*10,end=' ')
        else:
            print('{}*{} = {:<4}'.format(l,c,c*l),end=' ')
        c-=1
    print('')
    c = 9
    l-=1
'''
3
三角方向向右 双for循环
'''
print("三角方向向右，双for循环")
for l in range(1,10):
    for c in range(1,10):
        if l>=c:
            print('{}*{} = {:<4}'.format(l,c,c*l),end=' ')
    print()
print('=='*60)
for l in range(9,0,-1):
    for c in range(1,10):
        if l>=c:
            print('{}*{} = {:<4}'.format(l,c,c*l),end=' ')
    print()
print('***'*50,'\n\n')

'''
4
三角方向向左 双for循环
'''
print('三角方向向左 双for循环')
for l in range(1,10):
    for c in range(9,0,-1):
        if c > l:
            print(' '*10,end=' ')
        else:
            print('{}*{} = {:<4}'.format(l,c,c*l),end=' ')
    print()
print('=='*60)
for l in range(9,0,-1):
    for c in range(9,0,-1):
        if l < c :
            print(' ' * 10, end=' ')
        else:
            print('{}*{} = {:<4}'.format(l,c,c*l),end=' ')
    print()
'''
5
三角方向向右，while-for循环嵌套
'''
print('***'*50,'\n\n')
print("三角方向向右 while-for循环嵌套")
l = 1
# c = 1
while l<=9:
    for c in range(1, 10):
        if l>=c:
                print('{}*{} = {:<4}'.format(l,c,c*l),end=' ')
    print()
    # c = 1
    l+=1
print('=='*60,'\n')

l = 9
# c = 1
while l>=1:
    for c in range(1, 10):
        if l>=c:
                print('{}*{} = {:<4}'.format(l,c,c*l),end=' ')
    print()
    # c = 1
    l-=1
print('***'*50,'\n\n')
'''
6
三角方向向左，while-for循环嵌套
'''
print('三角方向向左 while-for循环嵌套')

l = 1
# c = 9
while l<=9 :
    for c in range(9, 0, -1):
        if c > l:
            print(' '*10,end=' ')
        else:
            print('{}*{} = {:<4}'.format(l,c,c*l),end=' ')
    print()
    # c = 9
    l+=1
print('=='*60,'\n')

l = 9
# c = 9
while l>=1 :
    for c in range(9, 0, -1):
        if l < c:
            print(' ' * 10, end=' ')
        else:
            print('{}*{} = {:<4}'.format(l, c, c * l), end=' ')
    print()
    # c = 9
    l-=1
print('***'*50,'\n\n')

'''
7
三角方向向右，for-while循环嵌套
'''
c = 1
print('三角方向向右，for-while循环嵌套')
for l in range(1,10):
    while c <= l:
        print('{:1}*{:1} = {:<4}'.format(l, c, l * c), end=' ')
        c += 1
    print('')
    c = 1
print('=='*60)
# c = 1
for l in range(9,0,-1):
    while c <= l:
        print('{}*{} = {:<4}'.format(l, c, l * c), end=' ')
        c += 1
    print()
    c = 1
# print('=='*60)
'''
8
三角方向向左，for-while循环嵌套
'''
print('***'*50,'\n\n')
print('三角方向向左，for-while循环嵌套')
c = 9
for l in range(1,10):
    while c >= 1:
        if c > l:
            print(' ' * 10, end=' ')
        else:
            print('{}*{} = {:<4}'.format(l, c, c * l), end=' ')
        c -= 1
    print('')
    c = 9
print('=='*60)
for l in range(9,0,-1):
    while c >= 1:
        if c > l:
            print(' ' * 10, end=' ')
        else:
            print('{}*{} = {:<4}'.format(l, c, c * l), end=' ')
        c -= 1
    print('')
    c = 9
# print('=='*60)
print('***'*50,'\n\n')

'''
可以把嵌套在内部的代码携程函数进行嵌套
'''